package org.company.earth.socket;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.SocketChannel;
import java.util.Date;

public class MyChannelClientSocket {
	public void startup() throws IOException {
		SocketChannel channel = SocketChannel.open();
		SocketAddress address = new InetSocketAddress(InetAddress.getLocalHost(), 8089);
		channel.socket().connect(address);
		ReadableByteChannel in = Channels.newChannel(System.in);
		ByteBuffer buf = ByteBuffer.allocate(1024);
		buf.put("aa".getBytes());
		while(true) {
			buf.clear();
			String time = new Date().toLocaleString();
			buf.put(time.getBytes());
			buf.flip();
			channel.write(buf);
		}
	}
}
